home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / libdmalloc / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.0 KB  |  79 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <malloc.h>
  18. #include <assert.h>
  19. #include <string.h>
  20. main(argc, argv)
  21. int argc;
  22. char **argv;
  23. {
  24.     extern int malloc_stacktrace_get_depth;
  25.     int i;
  26.     char *p;
  27.     void *ptr1, *ptr2, *ptr3, *ptr4;
  28.  
  29.  
  30.     malloc_stacktrace_get_depth = -1;
  31.  
  32.  
  33.     malloc_reset();
  34.  
  35.     for (i = 0; i < 5; ++i)
  36.     p = malloc(i);            /* 4 out of 5 leaks */
  37.     free(p);
  38.     free(realloc(realloc(malloc(5), 200), 1));
  39.  
  40.     if (argv[1]) {
  41.     if (!fopen(argv[1], "r"))    /* open the file and never close it */
  42.         perror(argv[1]);
  43.     }
  44.  
  45.  
  46.     ptr1 = malloc(5);
  47.     ptr2 = malloc(10);    /* should show up as a leak */
  48.     ptr3 = malloc(15);    /* should show up as a leak */
  49.  
  50.     ptr2 = malloc(20);
  51.  
  52.     free(ptr1);
  53.     free(ptr2);
  54.  
  55.     ptr4 = malloc(200);
  56.  
  57.     free(strdup("heh heh. this sucks. heh heh heh."));
  58.  
  59.     malloc_info(5);
  60.  
  61.     free(ptr4);
  62.     free(ptr4);            /* freed twice -- debug malloc should complain*/
  63.  
  64.  
  65.  
  66.     printf("Ha!\n");    /* just to make sure we got here without dumping core */
  67.     malloc_info(5);
  68.     malloc_info_cleanup();
  69.     malloc_info(1);
  70.     malloc_info_cleanup();
  71.     malloc_info(5);
  72.     malloc_info_cleanup();
  73.     malloc_info(1);
  74.     malloc_info_cleanup();
  75.     assert(malloc(1));
  76.     malloc_info_cleanup();    /* makes subsequent mallocs fail! */
  77.     assert(malloc(1));
  78. }
  79.